var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        id: "",
        city: "",
        point: {
            lat: "",
            lng: ""
        },
        page: 1,
        total_page: 0,
        stores: [],
        loading: !1,
        allLoaded: !1,
        isLoadMore: !0,
        openTemplate: 0
    },
    onLoad: function(t) {
        var a = this;
        console.log(t), t.name && (this.setData({
            titles: t.name
        }), wx.setNavigationBarTitle({
            title: t.name
        })), t.id && this.setData({
            id: t.id
        }), console.log(t.city, "undefined" != t.city, "dddddddd"), t.city && "undefined" != t.city ? (this.setData({
            city: t.city,
            point: JSON.parse(t.point)
        }), this.getStoresByCategoryIdLngAndLat()) : this._getLocation(function() {
            a.getStoresByCategoryIdLngAndLat();
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getStoresByCategoryIdLngAndLat: function() {
        var t = this, e = a.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-list-by-category-id-to-page"), o = a.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
        o.lng || (o.lng = "", o.lat = ""), e += "&category_id=" + this.data.id, e += "&lng=" + o.lng, 
        e += "&lat=" + o.lat, e += "&city_name=" + this.data.city, e += "&page=" + this.data.page, 
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    stores: e.data.data,
                    openTemplate: e.data.store_list_style || 0
                }), e.data.last_page ? t.setData({
                    total_page: e.data.last_page
                }) : e.data.lastPage && t.setData({
                    total_page: e.data.lastPage
                })) : (t.setData({
                    stores: []
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                }), setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 1500));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.page != this.data.total_page) if (this.data.page >= this.data.total_page) t.setData({
            loading: !0,
            allLoaded: !0
        }); else {
            this.setData({
                page: this.data.page + 1
            });
            var e = a.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-list-by-category-id-to-page"), o = a.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
            e += "&category_id=" + this.data.id, e += "&lng=" + o.lng, e += "&lat=" + o.lat, 
            e += "&city_name=" + this.data.city, e += "&page=" + this.data.page, a._getNetWork({
                url: e,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            loading: !1,
                            allLoaded: !1
                        });
                        var o = t.data.stores;
                        t.setData({
                            stores: o.concat(e.data.data)
                        });
                    } else t.setData({
                        page: t.data.page - 1,
                        loading: !0,
                        allLoaded: !0,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    }
});